﻿dojo.provide('app.index');
dojo.require('app.i18n');
dojo.requireLocalization('app.i18n');
dojo.require('app.utils.utils');
dojo.require('app.model');
dojo.require('app.data.services');
dojo.require('app.search');
dojo.require('app.mvc.View');
dojo.declare('app.index', [], {
	_wdgIds : [ 'tabContainer' ],

	startup : function(endpoints) {
		var bundle = app.i18n.getLocalization('app.i18n');
		var _self = this;
		Services.load(endpoints);
		dojo.parser.parse('mainContainer');
		var stack = dijit.byId('tabContainer');

		if (stack) {
			function view(page, data,resetEmpty) {
				console.log('Viewing ' + page);
				console.log(data);
				stack.selectChild(page + "View");
				app.mvc.View.get(page).set(data,resetEmpty);
			}
			dojo.subscribe('view/search', dojo.partial(view, 'search'));
			dojo.subscribe('view/add', dojo.partial(view, 'add'));
			dojo.subscribe('view/report', dojo.partial(view, 'report'));
		}

		app.mvc.View.register({
			'search' : new app.mvc.View({
				"contact.name" : null,
				"search.address" : null,
				"contact.country.isoCode" : null,
				"contact.country.countryCode" : null,
				"contact.country.id" : null,
				"contact.country.description" : null,
				"contact.country.version" : null,
				"type" : null
			}),
			'add' : new app.mvc.View({
				"contact.name" : null,
				"contact.email" : null,
				"contact.homePhone" : null,
				"contact.commercialPhone" : null,
				"contact.country.id" : null,
				"contact.id" : null,
				"contact.version" : null,
				"address.street.description" : null,
				"address.stNumber" : null,
				"address.complement" : null,
				"address.zip" : null,
				"address.country.id" : null,
				"address.district.id" : null,
				"address.state.id" : null,
				"address.city.id" : null,
				"address.id" : null,
				"address.version" : null,
				"address.json" : null,
				"address.lat" : null,
				"address.lng" : null,
				"address.centerLat" : null,
				"address.centerLng" : null,
				"comments" : null,
				"search.address" : null,
				"type" : null,
				"id" : null,
				"version" : null
			})
		});
		app.search.page.startup();
	}
});
app.index.page = new app.index();
